Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guide: Securing a WildFly app on k8s with OIDC #2087

Merged
merged 1 commit into from
Oct 7, 2024

Conversation

theashiot
Copy link

@theashiot theashiot commented Jan 31, 2024

cd /PATH/TO/ELYTRON/EXAMPLES/simple-webapp-oidc/charts
----

. Create a file `values.yml`.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @theashiot, apologies for the delayed response. I haven't gone through this in detail yet but yes, adding a file with the required configuration for k8s to the existing example would make sense.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @fjuma, i've created a PR to add the file: wildfly-security-incubator/elytron-examples#209

I'll updated the steps shortly.

Copy link
Author

@theashiot theashiot Feb 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updates the steps. Ready for review!

Please note that I haven't tested the steps for Quay. I have based them on https://www.wildfly.org/news/2023/06/16/deploy-on-kubernetes-with-helm/ . I'm facing some authentication problems with Quay.

I've tested the steps for Docker Hub.

@theashiot theashiot force-pushed the develop branch 2 times, most recently from 7303027 to b7060de Compare February 8, 2024 06:15
@theashiot theashiot marked this pull request as ready for review February 8, 2024 06:15

== Example Application

We use a simple web application in this guide that consists of a single https://github.com/wildfly-security/elytron-examples/blob/main/simple-webapp-oidc/src/main/java/org/wildfly/security/examples/SecuredServlet.java[servlet]. We show how to secure this servlet using OIDC. We will use the example in the https://github.com/wildfly-security-incubator/elytron-examples/tree/main/simple-webapp-oidc[simple-webapp-oidc] directory in the https://github.com/wildfly-security/elytron-examples[elytron-examples] repository.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, the examples repo is under the wildfly-security-incubator account.
https://github.com/wildfly-security-incubator/elytron-examples

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, fixed!

@theashiot
Copy link
Author

Hi @PrarthonaPaul,

I've made some updates. The steps for port-forwarding were missing. I've added them now. The steps work for dockerhub, but when i use quay, i get "ErrImagePull".

kubectl get pod
NAME                             READY   STATUS         RESTARTS      AGE
keycloak-65766c8d6b-tdnhn        1/1     Running        1 (42m ago)   75m
oidc-app-5d6f9974fd-srvrg        1/1     Running        0             26m
oidc-app-quay-79d48ff4df-lsb6l   0/1     ErrImagePull   0             68s

oidc-app-5d6f9974fd-srvrg is launched from dockerhub. oidc-app-quay-79d48ff4df-lsb6l is from quay.

I'm not able to figure out whats going wrong.

best,
ashwin

@PrarthonaPaul
Copy link
Contributor

Hi @PrarthonaPaul,

I've made some updates. The steps for port-forwarding were missing. I've added them now. The steps work for dockerhub, but when i use quay, i get "ErrImagePull".

kubectl get pod
NAME                             READY   STATUS         RESTARTS      AGE
keycloak-65766c8d6b-tdnhn        1/1     Running        1 (42m ago)   75m
oidc-app-5d6f9974fd-srvrg        1/1     Running        0             26m
oidc-app-quay-79d48ff4df-lsb6l   0/1     ErrImagePull   0             68s

oidc-app-5d6f9974fd-srvrg is launched from dockerhub. oidc-app-quay-79d48ff4df-lsb6l is from quay.

I'm not able to figure out whats going wrong.

best, ashwin

Hello @theashiot
It could be because you don't have your quay secret uploaded to k8.
Here are the steps to doing that for OpenShift: https://wildfly-security.github.io/wildfly-elytron/blog/in-progress-wildfly-feature-on-openshift/#configure-image-pull-secret

@theashiot
Copy link
Author

Thanks, @PrarthonaPaul for the reply! As discussed, i've removed all mentions of quay. I'll add quay-related info in a separate PR when i'm able to get it running.

best,
ashwin

:toc: macro
:toc-title:

You can secure your WildFly applications deployed on Kubernetes with OpenID Connect (OIDC). By using OIDC to secure applications, you delegate authentication to OIDC providers. This guide shows how to secure an example application deployed to WildFly on Kubernetes cluster running on your local machine, with OIDC using Keycloak as the OIDC provider.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/on Kubernetes cluster/on a Kubernetes cluster

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/OIDC provider/OpenID provider

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!


== Start Keycloak

We will be using Keycloak as our OIDC identity provider.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/OIDC identity provider/OpenID provider

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


We will be using Keycloak as our OIDC identity provider.

Follow the instructions, till "Log in to the Admin Console", provided in the https://www.keycloak.org/getting-started/getting-started-kube[Get started with Keycloak on Kubernetes] guide.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/till/up until

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

+
[source,subs=+quotes]
----
docker login __CONTAINER_REGISTRY__
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CONTAINER_REGISTRY seems to render a bit odd. Could we use <CONTAINER_REGISTRY> or something similar instead?

Copy link
Author

@theashiot theashiot May 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated all italics to <this_form>

docker tag simple-webapp-oidc __TAGGED_IMAGE__
----
+
Substitute __TAGGED_IMAGE__ as follows:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, renders in a way that's a bit hard to read.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@fjuma
Copy link
Contributor

fjuma commented May 7, 2024

Thanks for the post @theashiot! This looks great!

@PrarthonaPaul Would you be able to try out the steps from this post when you get a chance?

@theashiot
Copy link
Author

Thanks, @fjuma for the review! I've updated the content.

best,
ashwin

Copy link
Contributor

@PrarthonaPaul PrarthonaPaul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @theashiot
I have added some minor comments here.


You can secure your WildFly applications deployed on Kubernetes with OpenID Connect (OIDC). By using OIDC to secure applications, you delegate authentication to OpenID providers. This guide shows how to secure an example application deployed to WildFly on a Kubernetes cluster running on your local machine, with OIDC using Keycloak as the OpenID provider.

//toc::[]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please uncomment this to have the table of contents appear at the top of the guide.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


== Example Application

We use a simple web application in this guide that consists of a single https://github.com/wildfly-security/elytron-examples/blob/main/simple-webapp-oidc/src/main/java/org/wildfly/security/examples/SecuredServlet.java[servlet]. We show how to secure this servlet using OIDC. We will use the example in the https://github.com/wildfly-security-incubator/elytron-examples/tree/main/simple-webapp-oidc[simple-webapp-oidc] directory in the https://github.com/wildfly-security-incubator/elytron-examples[elytron-examples] repository.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the first link to https://github.com/wildfly-security-incubator/elytron-examples/blob/main/simple-webapp-oidc/src/main/java/org/wildfly/security/examples/SecuredServlet.java

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

* *Login settings*: Leave the fields blank for now.

+
For more information, see the Keycloak documentation on how to https://www.keycloak.org/docs/latest/server_admin/index.html#_oidc_clients[Managing OpenID Connect clients].
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be reworded to "... documentation on how to Manage OpenID Connect clients" or "... documentation on Managing OpenID Connect clients"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

used the latter, thanks


To build a Docker image from your application so that you can push it to a container repository, such as Docker Hub, follow these steps:

. Navigate to the application's directory.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be clearer to say "Navigate to the simple-webapp-oidc directory."

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed, updated


While our application is building, let's take a closer look at our application.

* Examine the https://github.com/wildfly-security/elytron-examples/blob/main/simple-webapp-oidc/pom.xml[pom.xml] file.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/wildfly-security/wildfly-security-incubator

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

== Resources

* https://www.wildfly.org/news/2023/06/16/deploy-on-kubernetes-with-helm/[Deploy on Kubernetes with Helm]
* https://docs.wildfly.org/30/Getting_Started_on_OpenShift.html#helm-charts[WildFly Helm Chart]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can update the version number to 33 to keep it up to date

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@theashiot
Copy link
Author

Thanks @PrarthonaPaul for the review! I've made the suggested changed. Mind having another look?

best,
ashwin

@theashiot
Copy link
Author

Hi @rsearls, would you mind trying out the steps in this post? Also please let me know if you think anything can be improved.

thanks,
ashwin

@rsearls
Copy link
Contributor

rsearls commented Sep 27, 2024

I'll look at it in the next couple of days


We will be using Keycloak as our OpenID provider.

Follow the instructions, up until "Log in to the Admin Console", provided in the https://www.keycloak.org/getting-started/getting-started-kube[Get started with Keycloak on Kubernetes] guide.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This installation guide has 2 sets of directions, one with the "Ingress addon"
and one without. You need to instruct the user whether this example requires
the "Ingress addon". Direct the user as to which set of instructions to use
as it relates to Ingress.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a line "This guide uses Keycloak with Ingress add-on enabled."


We will be using Keycloak as our OpenID provider.

Follow the instructions, up until "Log in to the Admin Console", provided in the https://www.keycloak.org/getting-started/getting-started-kube[Get started with Keycloak on Kubernetes] guide.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tell the user that during this step, "make note of the
initial admin user username, password and Keycloak Admin Console URL",
as it will be needed in the next step.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


. Log into the Keycloak Admin Console using the username and password you specified earlier.

. Create a new realm called *myrealm*. For more information, see the Keycloak documentation on how to https://www.keycloak.org/getting-started/getting-started-kube#_create_a_realm[create a realm].
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The directions linked to are old and not that helpful. Use this link and
instruct the user to Follow the directions in "Creating a realm".
https://www.keycloak.org/docs/latest/server_admin/#proc-creating-a-realm_server_administration_guide

Copy link
Author

@theashiot theashiot Oct 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated


. Create a new realm called *myrealm*. For more information, see the Keycloak documentation on how to https://www.keycloak.org/getting-started/getting-started-kube#_create_a_realm[create a realm].

. Add a role called *user*. This role will be required to access our simple web application. For more information, see the Keycloak documentation on how to https://www.keycloak.org/docs/latest/server_admin/index.html#assigning-permissions-using-roles-and-groups[create a role].
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The directions linked to are old and not that helpful. Use this link and
instruct the user to Follow the directions in "Creating a realm role",
following steps 1,2 and 4. Step 3 is optional
https://www.keycloak.org/docs/latest/server_admin/#proc-creating-realm-roles_server_administration_guide

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated.


. Add a new user named *alice*. Set an *email* address for this new user, we'll use *[email protected]*. For more information, see the Keycloak documentation on how to https://www.keycloak.org/getting-started/getting-started-kube#_create_a_user[create a user].

. Once the new user has been created, set a password for this new user from the *Credentials* tab.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this direction. If the user performed all the tasks listed for "create a user" they will have set the password already.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the link here to be consistent with the others. This one doesn't contain steps for adding a password, so added a sub-step.


. Once the new user has been created, set a password for this new user from the *Credentials* tab.

. From the *Role Mapping* tab, assign *alice* the *user* role. For more information, see the Keycloak documentation on how to https://www.keycloak.org/docs/latest/server_admin/index.html#proc-assigning-role-mappings_server_administration_guide[assign a role] to a user.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't make this a separate numbered step. Make it the 2nd paragraph of step 4. create user, because this task (e.g. tab) is accessed from the user details page.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made this a sub step.

. From the *Role Mapping* tab, assign *alice* the *user* role. For more information, see the Keycloak documentation on how to https://www.keycloak.org/docs/latest/server_admin/index.html#proc-assigning-role-mappings_server_administration_guide[assign a role] to a user.

. Create a new client as follows:
* *General Settings*:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These directions are more concise and clear

Click the General Settings image in the top left hand corner of the admin console
Click the "Clients" menu item
Click the "Create client" button
On the "Create client" page set the "Client type" to "OpenID Connect".
Set the "Client id" as, myclient.
Click the "Next" button at the bottom of the page
On the "Capability config" page the checkboxes for "Standard flow"
and "Direct access grants" should be selected.
Click the "Next" button at the bottom of the page
On the "Login settings" page no action is needed at this time.
Click the "Save" button at the bottom of the page.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed, updated with slight modifications.

* *Login settings*: Leave the fields blank for now.

+
For more information, see the Keycloak documentation on https://www.keycloak.org/docs/latest/server_admin/index.html#_oidc_clients[Managing OpenID Connect clients].
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would remove this reference. It just confuses the whole situation because it does not accurately reflect the current screen layout.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed


* For Docker Hub, use `<USERNAME>/simple-webapp-oidc`.

. Verify that you see the tagged image in Docker images.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this step. The image was verified in the previous section. There is no reason to re-verify it here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

. Navigate to the `simple-webapp-oidc` directory.


. Use the `wildfly-maven-plugin` plugin to create a docker image.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the reference to wildfly-maven-plugin here. It is distracting from the current task and you discuss it at a more appropriate time in a future section.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


== Finish Configuring Keycloak

From your *myclient* client in the Keycloak Administration Console, in the client settings, set *Valid Redirect URI* to `http://localhost:8080/simple-webapp-oidc/secured/pass:[*]` then click *Save*.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These directions are more concise and clear

Click the General Settings image in the top left hand corner of the admin console
Click the "Clients" menu item
Click on "myclient" from the list on the Clients page.
Scroll down to the "Access settings" section on the page.
In field, "Valid redirect URIs set the value to http://localhost:8080/simple-webapp-oidc/secured/pass:[*]
Click the "Save" button at the bottom of the page.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed, updated with slight modification.

@theashiot
Copy link
Author

Thank you so much @rsearls for the review and wonderful suggestions! I've made the suggested changes. Would you mind having another look?

best,
ashwin

@rsearls
Copy link
Contributor

rsearls commented Oct 7, 2024

This look fine. I have no more comments

@theashiot
Copy link
Author

Thanks a lot @rsearls!!
@fjuma I've updated the filename and the date in the post as well.

best,
ashwin

@fjuma fjuma removed the fixme label Oct 7, 2024
@fjuma
Copy link
Contributor

fjuma commented Oct 7, 2024

Thanks @theashiot and @rsearls!

@fjuma fjuma merged commit 2579aaf into wildfly-security:develop Oct 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants